package study.concurrent.lock.service;

import cn.hutool.core.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import study.concurrent.lock.support.utils.SleepUtils;

/**
 * Mutex
 */
@Slf4j
@Service
public class MutexService {

    public void doMutex() {
        long sec = RandomUtil.randomInt(3, 6);
        log.info(">>>>>> 开始临界区, 需要 {} 秒", sec);
        SleepUtils.sleepWaitFor(sec);
        log.info(">>>>>> 结束临界区");
    }

    public void doMutex(Long sec) {
        log.info(">>>>>> 临界区代码执行开始, 需要 {} 秒", sec);
        SleepUtils.sleepWaitFor(sec);
        log.info(">>>>>> 临界区代码执行结束");
    }
}
